from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC


class IframePage():

    def __init__(self, driver):
        self.driver = driver
        self.url = "http://localhost:8080/iframe"
        # iframe xpath
        self.iframe_xpath = "//iframe[@id='map']"  # iframe xpath
        self.search_input_xpath = "//input[@id='s']"    # iframe内部输入框xpath
        self.first_data_xpath = "//div[@class='archive-list']//descendant::a[1]"    # 新窗口第一条数据xpath

    @property
    def iframe_ele(self):
        """
        获取iframe元素
        :return:
        """
        wait = WebDriverWait(self.driver, 10)
        iframe_xpath = wait.until(EC.visibility_of_element_located((By.XPATH, self.iframe_xpath)))
        return iframe_xpath

    @property
    def search_input_ele(self):
        """
        获取ifrmae里面的搜索框
        :return:
        """
        wait = WebDriverWait(self.driver, 10)
        search_input = wait.until(EC.visibility_of_element_located((By.XPATH, self.search_input_xpath)))
        return search_input

    @property
    def first_data_ele(self):
        """
        获取搜索后的第一条数据元素
        :return:
        """
        wait = WebDriverWait(self.driver, 10)
        first_data = wait.until(EC.visibility_of_element_located((By.XPATH, self.first_data_xpath)))
        return first_data